#include "GameLib.h"

int main(int argc, char *argv[])
{
	
	CGame Game;
	Game.Run();

	return 0;
}

int CGame::Run()
{
	
	Video.Init();
	Sound.SoundInit();
	MainLoop();
	
	CleanUp();
	return 0;
}

void CGame::MainLoop()
{
	const float FPS = 35.0;

	Uint32 last_time = SDL_GetTicks();
	Uint32 wait;
	int frames_drawn = 0;

	//SDL_ShowCursor(SDL_DISABLE);
	//SDL_WM_GrabInput(SDL_GRAB_ON);

	do
	{
		try
		{
			ProcessEvents();
			Video.Draw();
		}
		catch(...)
		{
			printf("Error");
			game_stop = true;
		}
		
		frames_drawn++;
		wait = SDL_GetTicks() - last_time;
		if(wait < 1000.0 / FPS) SDL_Delay( (Uint32)(1000.0 / FPS - wait) );
		last_time = SDL_GetTicks();
	}while(!game_stop);

	//SDL_WM_GrabInput(SDL_GRAB_OFF);
	//SDL_ShowCursor(SDL_ENABLE);
}

void CGame::CleanUp()
{
	SDL_Quit();
}